//
//  UIButton+Extension.swift
//  MLSMircoBlog
//
//  Created by 袁航 on 15/8/2.
//  Copyright © 2015年 yuanhang. All rights reserved.
//

import UIKit
extension UIButton {
    // 便利构造函数(当默认赋初始值后,会生成两个便利构造函数,一个具有附有初始值的参数,一个没有)
    convenience init(image: UIImage?, title: String?, fontSize: CGFloat = 12, titleColor: UIColor = UIColor.darkGrayColor(),backGroundColor: UIColor = UIColor(white: 0.95, alpha: 1)) {
        self.init()
        setTitle(title, forState: UIControlState.Normal)
        setImage(image, forState: UIControlState.Normal)
        setTitleColor(titleColor, forState: UIControlState.Normal)
        backgroundColor = backGroundColor
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        
    }
    convenience init(nomarlImageName: String?, highlightImageName: String?) {
        self.init()
        if let nomarl = nomarlImageName {
            setImage(UIImage(named: nomarl), forState: UIControlState.Normal)
            sizeToFit()
        }
        if let highlight = highlightImageName {
            setImage(UIImage(named: highlight), forState: UIControlState.Highlighted)
            sizeToFit()
        }
    }
    convenience init(nomarlImage: UIImage?, highlightImage: UIImage?) {
        self.init()
        setImage(nomarlImage, forState: UIControlState.Normal)
        setImage(highlightImage, forState: UIControlState.Highlighted)
        sizeToFit()
    }
}
